Generic PackageArgument#6856
Conversation
|
|
||
| namespace NuGet.CommandLine.XPlat.Utility | ||
| { | ||
| internal static class PackageArgumentFactoryUtility |
There was a problem hiding this comment.
The factory isn't needed for generics, instead you can create a static method on the class and have it create typed instances
https://dotnetfiddle.net/jFHQhx
public static PackageArgument<TVersion> Create(string id, TVersion version, IEqualityComparer<TVersion?> versionComparer)
{
return new PackageArgument<TVersion>(versionComparer)
{
Id = id,
Version = version,
};
}There was a problem hiding this comment.
Thanks for the suggestion. that’s a really good point. Having a static method on the generic class would definitely simplify the design and make it more flexible.
The reason I introduced the factory, though, was to make it easier for callers so they don’t have to remember to pass in the comparer every time. It ensures consistency by automatically using the right comparer for NuGetVersion and VersionRange cases.
|
Thank you for the reviews. I will be closing this PR since we went ahead with the other implementation. |
Bug
Fixes:
Description
This PR introduces a generic
PackageArgumenttype. Previously, we hadPackagetype which only supported VersionRange versions. This new generic enables callers to implement it with both NuGetVersion and VersionRange.PR Checklist